import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class LinesPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.loan = By.XPATH, '//*[@id="mlayout"]/div[2]/div[2]/div[1]/a/em'
        self.application = By.XPATH, '//*[@id="mlayout"]/div[2]/div[2]/div[3]/div[2]/dl/dd[4]/a'
        self.Yuan = By.XPATH, '//*[@id="amount_account"]'
        self.illustrate = By.XPATH, '//*[@id="mamountapply"]/div[3]/textarea'
        self.captcha = By.XPATH, '//*[@id="verifycode"]'
        self.submit = By.XPATH, '//*[@id="mamountapply"]/div[5]/input'
        self.money = (By.XPATH, '//*[@id="amount_list"]/tr[1]/td[3]')

    def lines(self, yuan, illustrate, captcha):
        time.sleep(2)
        self.base_click(self.loan)
        self.base_click(self.application)
        self.base_input(self.Yuan, yuan)
        self.base_input(self.illustrate, illustrate)
        self.base_input(self.captcha, captcha)
        self.base_click(self.submit)

    def get_lines_result(self):
        result = self.fd_element(self.money).text
        return result
